<template>
  <div>
    <div class="top">
      <div class="goback" @click="$router.go(-1)">
        <van-icon name="arrow-left"/>
      </div>
      <div class="top_tab">
        <div :class="{topbar_act:0 == pagedata.toptab}" @click="tabchange(0)">商品</div>
        <div :class="{topbar_act:1 == pagedata.toptab}" @click="tabchange(1)">评价</div>
      </div>
    </div>
    <div v-if="pagedata.toptab==0" class="product">
      <div class="slider">
        <van-swipe :autoplay="3000">
          <van-swipe-item v-for="(image, index) in data.img" :key="index">
            <img v-lazy="image" :src="image" style="width: 100%;height: auto"/>
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="product_info">
        <div class="title f16">{{data.title}}</div>
        <div class="subtitle ">
          <tag></tag>
          <span class="fs12">{{data.sub_title}}</span>
        </div>
        <div class="detail">
          <prize v-bind:prize="spec.prize"></prize>
          <span class="yjia">¥{{spec.cost_price}}</span>
          <span class="chandi">产地:{{data.product}}</span>
        </div>
        <div class="server">
          <ul>
            <li>
              <i>．</i>支持２４小时无理由退货
            </li>
          </ul>
        </div>
      </div>
      <div class="customer_select">
        <div class="guige">规格:
          <div v-for="(item,index) in data.type" :class="{guige_act:index == pagedata.spec}" @click="tab(index)" class="guige_son">{{item.unit}}</div>
          <!--<div class="guige_son">350g/份</div>-->
        </div>
        <div class="shuliang">数量:
          <span class="sisuqi">
          <van-stepper v-model="spec.count"
                       integer
                       :min="1"
                       :max="spec.stock"
                       :step="1"/>
            </span>
        </div>
        <div class="cusinfo">现在下单,预计明日送达</div>
      </div>
      <div class="comment">
        <div @click="tabchange(1)" class="fs16 title">评论</div><div/>
        <div class="info">
          <img class="touxiang" src="https://www.baidu.com/img/baidu_jgylogo3.gif"/>
          <span class="name">甲甲</span>
          <span class="time">2018-01-11</span>
        </div>
        <div class="neirong">
          <div class="rank">
            <van-rate
              v-model="value"
              :size="15"
              :count="5"
              color="#2ba"
              disabled-color="#ff7f04"
              disabled
            />
          </div>
          <div class="comment_info">
            啊啊啊啊啊
          </div>
          <div class="comment_img">
            <img  src="https://www.baidu.com/img/baidu_jgylogo3.gif"/>
            <img  src="https://www.baidu.com/img/baidu_jgylogo3.gif"/>
            <img  src="https://www.baidu.com/img/baidu_jgylogo3.gif"/>
          </div>
        </div>
      </div>
      <div style="height: 10px"></div>
      <favourite v-bind:title="pagedata.favourite" v-bind:goods="favorite"></favourite>
      <div style="height: 50px"></div>
    </div>
    <div v-if="pagedata.toptab==1" class="comment">
      <div class="comment_tab">
        <div>评价(22)
        </div>
        <div>有图(22)
        </div>
      </div>
      <div class="tag_cloud">
        <div class="tag"> 酸甜可扣<span>115</span></div>
      </div>
      <div class="pingjia">
        <div class="comment">
          <div class="info">
            <img class="touxiang" src="https://www.baidu.com/img/baidu_jgylogo3.gif"/>
            <span class="name">甲甲</span>
            <span class="time">2018-01-11</span>
          </div>
          <div class="neirong">
            <div class="rank">
              <van-rate
                v-model="value"
                :size="15"
                :count="5"
                color="#2ba"
                disabled-color="#ff7f04"
                disabled
              />
            </div>
            <div class="comment_info">
              啊啊啊啊啊
            </div>
            <div class="comment_img">
              <img  src="https://www.baidu.com/img/baidu_jgylogo3.gif"/>
              <img  src="https://www.baidu.com/img/baidu_jgylogo3.gif"/>
              <img  src="https://www.baidu.com/img/baidu_jgylogo3.gif"/>
            </div>
          </div>
        </div>
      </div>
    </div>

    <cartnav v-on:addtoCart="addtoCart"></cartnav>
  </div>

  <!--&lt;!&ndash;这是:{{$route.params.infoid}}商品&ndash;&gt;-->
  <!--<div @click="$router.go(-1)">返回</div>-->

</template>

<script>
  import Vue from 'vue';
  import {Lazyload} from 'vant';
  Vue.use(Lazyload, {loading: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1533554786030&di=e513a87c587b7003c9cc59d005e4e9e5&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F017ebd58d921baa801219c775b6f3b.gif "});
  import tag from './plugs/tags'
  import prize from './plugs/prize'
  import favourite from './../common/favourite'
  import cartnav from './../common/bottom-cart'
  import store from '../../vuex/store'
  export default {
    name: "info",
    components: {
      prize,
      tag,
      favourite,
      cartnav
    },
    methods: {
      tabchange: function (v) {//切换评论和详情
        this.pagedata.toptab = v
      },
      tab:function (v) {//切换规格
        this.pagedata.spec=v
        this.spec=this.data.type[v]
      },
      addtoCart(){
        var good={
          id:this.data.id,
          img:this.data.thumbnail,
          name:this.data.title,
          uid:this.data.type[this.pagedata.spec].typeid,
          prize:this.data.type[this.pagedata.spec].prize,
          unit:this.data.type[this.pagedata.spec].unit,
          count:this.spec.count,//数量
          sub:this.data.type[this.pagedata.spec].info,
          stock:this.data.type[this.pagedata.spec].stock,
          select:true,
        }
        store.commit('addgoodtoCart',good)
        store.commit('countchange',{
          id:this.data.id,
          uid:good.id,
          num:good.count
        })
      }
    },
    data: function () {
      return {
        pagedata: {
          toptab: 0,//默认商品页面
          favourite:"大家都在买",
          spec:0,//规格
        },
        spec:{
          count:0,
          typeid: "20g/份",//
          unit: "",//规格单位
          prize: 0,//真实价格
          cost_price: 0,//原价
          stock: 0,//库存
          info: ""//说明
        },
        value: 20,
        favorite: [//大家都在买
          {
            id: "123",//商品id
            typeid: "123",//货物id
            title: "苹果",
            prize: 55.0,//价格
            img:"https://www.baidu.com/img/baidu_jgylogo3.gif",
            unit: "20g/份",
            stock: 10,//库存
          }, {
            id: "123",//商品id
            typeid: "456",//货物id
            title: "梨子",
            prize: 55.0,//价格
            unit: "20g/份",
            stock: 10,//库存
          }, {
            id: "123",//商品id
            typeid: "789",//货物id
            title: "banana",
            prize: 55.0,//价格
            unit: "20g/份",
            stock: 10,//库存
          }, {
            id: "123",//商品id
            typeid: "000",//货物id
            title: "梨子",
            prize: 55.0,//价格
            unit: "20g/份",
            stock: 10,//库存
          }, {
            id: "123",//商品id
            typeid: "012",//货物id
            title: "banana",
            prize: 55.0,//价格
            unit: "20g/份",
            stock: 10,//库存
          },
        ]//大家都在买

      }
    },
    computed: {
      data(){
        return store.state.infopage
      }
    },
    mounted() {
      var id = window.location.href.split("uid?=")[1];

      store.commit('getgoodinfo',id)
      this.spec=this.data.type[this.pagedata.spec]
    }
  }
</script>

<style lang="less" scoped>
  div {
    box-sizing: border-box;
    /*background-color: #fff;*/
  }

  .top {
    height: 40px;
    background-color: #fff;
    overflow: hidden;
    border_bottom: 1px solid @_grey;
  }

  .goback {
    width: 50px;
    height: 100%;
    font-size: 20px;
    color: @_blk;
    float: left;
    margin-left: 10px;
    box-sizing: border-box;
    padding-top: 10px;
  }

  .top_tab {
    width: 100px;
    margin: 0 auto;
    height: 100%;
  }

  .top_tab div {
    width: 50%;
    height: 100%;
    text-align: center;
    line-height: 50px;
    position: relative;
    float: left;
  }

  .top_tab div::after {
    position: absolute;
    width: 30px;
    bottom: 0;
    left: 50%;
    margin-left: -15px;
    content: " ";
  }

  .topbar_act {
    color: @_green;
  }

  .topbar_act::after {
    border-bottom: 2px solid @_green;
  }

  .slider {
    height: 320px;
  }

  .van-swipe {
    height: 100%;
    line-height: 320px;
  }

  .product_info {
    background-color: #fff;
    height: auto;
    margin-bottom: 10px;
  }

  .title {
    box-sizing: border-box;
    padding: 0 5px;
    color: @_blk;
    line-height: 35px;
  }

  .subtitle {
    line-height: 25px;
    box-sizing: border-box;
    padding: 0 5px;
    color: @_grey;
  }

  .yjia {
    text-decoration: line-through
  }

  .chandi {
    float: right;
  }

  .detail {
    box-sizing: border-box;
    padding: 0 5px;
    line-height: 30px;
    border-bottom: 1px solid @_lgrey;
  }

  .server {
    padding: 7px 5px;
  }

  .customer_select {
    background: #fff;
    height: auto;
  }

  .guige {
    height: 50px;
    line-height: 50px;
    padding: 0 5px;
    border-bottom: 1px solid @_lgrey;
  }

  .guige_son {
    border: 1px solid @_grey;
    border-radius: 5px;
    display: inline-block;
    padding: 5px 8px;
    line-height: 15px;
  }

  .guige_act {
    border: 1px solid @_green;
    color: @_green;
    margin: 0 10px;
  }

  .shuliang {
    padding: 5px 8px;
    line-height: 50px;
    vertical-align: middle
  }

  .sisuqi {
    vertical-align: middle;
    display: inline-block;
    line-height: 0;
    /*margin-bottom:10px;*/
  }

  .cusinfo {
    padding: 5px 8px;
  }

  .comment_tab {
    border-bottom: 1px solid @_lgrey;
    border-top: 1px solid @_lgrey;
    /*line-height: 37px;*/
    text-align: center;
    overflow: hidden;
    background-color: #fff;

  }

  .comment_tab div {
    width: 50%;
    float: left;
    height: 14px;
    line-height: 14px;
    margin: 10px auto;
  }

  .comment_tab div:first-child {
    border-right: 1px solid @_lgrey;
  }

  .tag_cloud {
    height: auto;
    padding: 8px 15px;
    margin-bottom: 10px;
    background-color: #fff;
  }

  .tag {
    display: inline-block;
    border-right: 1px solid @_lgrey;
    padding: 0 15px;
  }

  .pingjia {
    background-color: #fff;
  }

  .info {
    line-height: 30px;
    width: 95%;
    margin: auto;
    padding-bottom: 10px;
    border-bottom: 1px solid @_lgrey;
  }

  .time {
    float: right;
  }

  .touxiang {
    border-radius: 50%;
    height: 25px;
    width: 25px;
    margin-right: 10px;
    margin-top: 3px;
  }
  .neirong{
    padding: 0 15px;
  }
  .rank{
    line-height: 40px;
  }
  .comment_img img {
    height: 60px;
    width: 60px;
    margin-right: 10px;
  }
  .comment_img{
    padding: 10px 0;
  }
  .product .comment{
    background-color: #ffffff;
    margin-top: 10px;
  }
  .comment .title{
    line-height: 30px;
    padding-left: 10px;
  }
</style>
